package org.xtext.tcc.generator;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.eclipse.xtext.xtend2.lib.StringConcatenation;
import org.xtext.tcc.TccdslExtensions;
import org.xtext.tcc.tccdsl.Attribute;
import org.xtext.tcc.tccdsl.Entity;
import org.xtext.tcc.tccdsl.Function;

@SuppressWarnings("all")
public class ModelExtensions extends TccdslExtensions {
  
  public StringConcatenation compile(final Entity e) {
    StringConcatenation _builder = new StringConcatenation();
    {
      EObject _eContainer = e.eContainer();
      if ((_eContainer instanceof org.xtext.tcc.tccdsl.Package)) {
        _builder.append("package ");
        String _packageName = this.packageName(e);
        _builder.append(_packageName, "");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("import java.util.List;");
    _builder.newLine();
    {
      EObject _eContainer_1 = e.eContainer();
      if ((_eContainer_1 instanceof org.xtext.tcc.tccdsl.Package)) {
        _builder.append("import ");
        String _packageName_1 = this.packageName(e);
        _builder.append(_packageName_1, "");
        _builder.append(".control.");
        String _name = e.getName();
        _builder.append(_name, "");
        _builder.append("Controller;");
        _builder.newLineIfNotEmpty();} else {
        _builder.append("import control.");
        String _name_1 = e.getName();
        _builder.append(_name_1, "");
        _builder.append("Controller;");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    StringConcatenation _classes = this.classes(e);
    _builder.append(_classes, "");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  public StringConcatenation classes(final Entity e) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class ");
    String _name = e.getName();
    _builder.append(_name, "");
    {
      Entity _superEntity = e.getSuperEntity();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_superEntity, null);
      if (_operator_notEquals) {
        _builder.append(" extends ");
        Entity _superEntity_1 = e.getSuperEntity();
        String _name_1 = _superEntity_1.getName();
        _builder.append(_name_1, "");
      }
    }
    _builder.append("{");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.newLine();
    {
      EList<Attribute> _attributes = e.getAttributes();
      for(Attribute a : _attributes) {
        _builder.append("\t");
        _builder.append("private ");
        StringConcatenation _variable = this.variable(a);
        _builder.append(_variable, "	");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("\t");
    _builder.newLine();
    {
      EList<Attribute> _attributes_1 = e.getAttributes();
      for(Attribute a_1 : _attributes_1) {
        _builder.append("\t");
        _builder.append("public ");
        StringConcatenation _typeDeclaration = this.typeDeclaration(a_1);
        _builder.append(_typeDeclaration, "	");
        _builder.append(" get");
        String _name_2 = a_1.getName();
        String _firstUpper = StringExtensions.toFirstUpper(_name_2);
        _builder.append(_firstUpper, "	");
        _builder.append("(){");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.append("return ");
        String _name_3 = a_1.getName();
        _builder.append(_name_3, "		");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public void set");
        String _name_4 = a_1.getName();
        String _firstUpper_1 = StringExtensions.toFirstUpper(_name_4);
        _builder.append(_firstUpper_1, "	");
        _builder.append("(");
        StringConcatenation _variable_1 = this.variable(a_1);
        _builder.append(_variable_1, "	");
        _builder.append("){");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.append("this.");
        String _name_5 = a_1.getName();
        _builder.append(_name_5, "		");
        _builder.append(" = ");
        String _name_6 = a_1.getName();
        _builder.append(_name_6, "		");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
      }
    }
    {
      EList<Function> _functions = e.getFunctions();
      for(Function f : _functions) {
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public ");
        StringConcatenation _functionHeader = this.functionHeader(f);
        _builder.append(_functionHeader, "	");
        _builder.append("{");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        String _name_7 = e.getName();
        String _firstUpper_2 = StringExtensions.toFirstUpper(_name_7);
        _builder.append(_firstUpper_2, "		");
        _builder.append("Controller.");
        String _name_8 = f.getName();
        _builder.append(_name_8, "		");
        _builder.append("(");
        String _parameterDeclaration = this.parameterDeclaration(f);
        _builder.append(_parameterDeclaration, "		");
        _builder.append(");");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
      }
    }
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
}